package com.dupengcheng.subject.domain.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.dupengcheng.subject.common.enums.IsDeleteEnum;
import com.dupengcheng.subject.domain.convert.SubjectLabelConvert;
import com.dupengcheng.subject.domain.entity.SubjectLabelBO;
import com.dupengcheng.subject.domain.service.SubjectLabelDomainService;
import com.dupengcheng.subject.infra.basic.entity.SubjectLabel;
import com.dupengcheng.subject.infra.basic.service.SubjectLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class SubjectLabelDomainServiceImpl implements SubjectLabelDomainService {

    @Resource
    private SubjectLabelService labelService;



    @Override
    public boolean add(SubjectLabelBO subjectLabelBO) {
        if (log.isInfoEnabled()){
            log.info("SubjectLabelController.add.bo:{}",
                    JSONObject.toJSONString(subjectLabelBO));
        }
       SubjectLabel subjectLabel= SubjectLabelConvert.INSTANCE
                .convertBoToLabel(subjectLabelBO);
        subjectLabel.setIsDeleted(IsDeleteEnum.UN_DELETE.getCode());
        return labelService.insert(subjectLabel)>0;
    }

    @Override
    public boolean update(SubjectLabelBO subjectLabelBO) {
        if (log.isInfoEnabled()){
            log.info("SubjectLabelController.add.bo:{}",
                    JSONObject.toJSONString(subjectLabelBO));
        }
        SubjectLabel subjectLabel= SubjectLabelConvert.INSTANCE
                .convertBoToLabel(subjectLabelBO);
        subjectLabel.setIsDeleted(IsDeleteEnum.UN_DELETE.getCode());
        return labelService.update(subjectLabel)>0;
    }

    @Override
    public boolean delete(SubjectLabelBO subjectLabelBO) {
        if (log.isInfoEnabled()){
            log.info("SubjectLabelController.add.bo:{}",
                    JSONObject.toJSONString(subjectLabelBO));
        }
        SubjectLabel subjectLabel= SubjectLabelConvert.INSTANCE
                .convertBoToLabel(subjectLabelBO);
        subjectLabel.setIsDeleted(IsDeleteEnum.DELETE.getCode());
        return labelService.update(subjectLabel)>0;
    }

    @Override
    public List<SubjectLabelBO> query(SubjectLabelBO subjectLabelBO) {
        if (log.isInfoEnabled()){
            log.info("SubjectLabelController.add.bo:{}",
                    JSONObject.toJSONString(subjectLabelBO));
        }
        SubjectLabel subjectLabel= SubjectLabelConvert.INSTANCE
                .convertBoToLabel(subjectLabelBO);
        subjectLabel.setIsDeleted(IsDeleteEnum.UN_DELETE.getCode());
        List<SubjectLabel>  subjectLabelList=labelService.queryBatch(subjectLabel);
        List<SubjectLabelBO> subjectLabelBOList=SubjectLabelConvert.INSTANCE
                .convertLabelToBOList(subjectLabelList);
        return subjectLabelBOList;
    }
}
